

import 'package:bike_ride/api/api_defines.dart';
import 'package:bike_ride/common/net/base_repository.dart';
import 'package:bike_ride/common/net/dio_client.dart';
import 'package:bike_ride/common/net/dio_response.dart';
import 'package:bike_ride/common/util/model_utils.dart';
import 'package:bike_ride/generated/l10n.dart';
import 'package:dio/dio.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

class CmdRepository extends BaseRepository{


  /// 寻车铃
  static Future<bool> findBikeIdl({
    CancelToken? cancelToken,
    num? lat,
    num? lng,
    required String vid,
  }) async {
    EasyLoading.show(status: '${S.current.downingCmd}...');
    final response = await DioClient().doPost(kAPIURLFindBike,
        cancelToken: cancelToken, data: {'vid': vid,'lat': lat, 'lng': lng});
    if (response.statusCode == REQUEST_SUCCESS) {
      EasyLoading.showSuccess(S.current.downingCmdSuccess);
      return true;
    } else {
      DioClient.showError(response);
      return false;
    }
  }

  /// 车辆刷新Gps
  static Future<LatLng?> bikeRefreshGpsIdl({
    CancelToken? cancelToken,
    required String vid,
  }) async {
    final response = await DioClient().doPost(kAPIURLBikeRefreshGps,
        cancelToken: cancelToken, data: {'vid': vid,});
    if (response.statusCode == REQUEST_SUCCESS) {
      if(parseToDouble(response.data['lat'])>0 && parseToDouble(response.data['lng']) > 0) {
        return LatLng(parseToDouble(response.data['lat']), parseToDouble(response.data['lng']));
      }
    } else {
      DioClient.showError(response);
    }
    return null;
  }


}